<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>X2Knowledge - 知识提取器工具 - API文档</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    <!-- 引入Marked库用于Markdown渲染 -->
    <script src="https://cdn.jsdelivr.net/npm/marked@4.3.0/marked.min.js"></script>
    <!-- 引入highlight.js用于代码高亮 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11.7.0/styles/github.min.css">
    <script src="https://cdn.jsdelivr.net/npm/highlight.js@11.7.0/highlight.min.js"></script>
    <style>
        .api-section {
            background-color: #f9f9f9;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        
        .endpoint {
            background-color: #e9f5ff;
            padding: 10px;
            border-radius: 4px;
            font-family: monospace;
            margin: 10px 0;
        }
        
        .method {
            display: inline-block;
            background-color: #4CAF50;
            color: white;
            padding: 2px 8px;
            border-radius: 4px;
            font-weight: bold;
        }
        
        pre {
            background-color: #f1f1f1;
            padding: 15px;
            border-radius: 4px;
            overflow-x: auto;
        }
        
        code {
            font-family: monospace;
        }
        
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 15px 0;
        }
        
        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        
        th {
            background-color: #f2f2f2;
        }
        
        .test-section {
            background-color: #f0f8ff;
            border-radius: 8px;
            padding: 20px;
            margin-top: 30px;
        }
        
        .response-container {
            background-color: #f5f5f5;
            border: 1px solid #ddd;
            border-radius: 4px;
            padding: 15px;
            margin-top: 20px;
            max-height: 300px;
            overflow-y: auto;
            display: none;
        }
        
        .nav-link {
            display: inline-block;
            margin-right: 15px;
            color: #3498db;
            text-decoration: none;
            font-weight: bold;
        }
        
        .nav-link:hover {
            text-decoration: underline;
        }
        
        .tab-content {
            margin-top: 20px;
        }
        
        .loading {
            display: none;
            text-align: center;
            margin: 20px 0;
        }
        
        .spinner {
            border: 4px solid rgba(0, 0, 0, 0.1);
            border-radius: 50%;
            border-top: 4px solid #3498db;
            width: 30px;
            height: 30px;
            animation: spin 1s linear infinite;
            margin: 0 auto;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .tab-controls {
            display: flex;
            margin-bottom: 20px;
            border-bottom: 1px solid #ddd;
        }
        
        .tab-button {
            padding: 10px 20px;
            border: none;
            background: none;
            cursor: pointer;
            font-weight: bold;
            color: #555;
        }
        
        .tab-button.active {
            border-bottom: 3px solid #3498db;
            color: #3498db;
        }
        
        .api-tab-controls {
            display: flex;
            margin-bottom: 20px;
            border-bottom: 1px solid #ddd;
        }
        
        .api-tab-button {
            padding: 10px 20px;
            border: none;
            background: none;
            cursor: pointer;
            font-weight: bold;
            color: #555;
        }
        
        .api-tab-button.active {
            border-bottom: 3px solid #3498db;
            color: #3498db;
        }
        
        .api-tab-content {
            display: none;
        }
        
        .api-tab-content.active {
            display: block;
        }
        
        /* API目录样式 */
        .api-toc-list {
            list-style: none;
            padding: 0;
            margin: 0;
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
        }
        
        .api-toc-list li {
            background-color: #f1f8ff;
            border-radius: 5px;
            padding: 0;
            transition: all 0.2s ease;
        }
        
        .api-toc-list li a {
            display: block;
            padding: 8px 12px;
            color: #0366d6;
            text-decoration: none;
            font-weight: 500;
        }
        
        .api-toc-list li:hover {
            background-color: #daeaff;
            transform: translateY(-2px);
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        
        /* 代码示例区域样式 */
        #api-examples {
            background-color: #f6f8fa;
        }
        
        #api-examples h2 {
            border-bottom: 2px solid #0366d6;
            padding-bottom: 8px;
        }
        
        #api-examples h3 {
            margin-top: 25px;
            color: #24292e;
        }
        
        #api-examples pre {
            background-color: #1e1e1e;
            color: #e6e6e6;
            padding: 15px;
            border-radius: 6px;
            overflow-x: auto;
        }
        
        #api-examples code {
            font-family: 'Courier New', Courier, monospace;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="language-switch">
            <button class="language-btn active" data-lang="zh">中文</button>
            <button class="language-btn" data-lang="en">English</button>
        </div>
        
        <header>
            <h1 data-i18n="api-docs-title">X2Knowledge API 文档</h1>
            <div class="nav-links">
                <a href="/" class="nav-link" data-i18n="back-to-home">返回首页</a>
                <a href="#api-toc" class="nav-link">API目录</a>
                <a href="#api-examples" class="nav-link">代码示例</a>
            </div>
        </header>

        <main>
            <section id="api-toc" class="api-section">
                <h2>API目录</h2>
                <ul class="api-toc-list">
                    <li><a href="#api-text">文档文本提取 API</a></li>
                    <li><a href="#api-markitdown-md">MarkItDown转MD API</a></li>
                    <li><a href="#api-docling-md">Docling转MD API</a></li>
                    <li><a href="#api-docling-html">Docling转HTML API</a></li>
                    <li><a href="#api-docling-json">Docling转JSON API</a></li>
                    <li><a href="#api-marker-md">Marker转MD API</a></li>
                    <li><a href="#api-marker-html">Marker转HTML API</a></li>
                    <li><a href="#api-marker-json">Marker转JSON API</a></li>
                    <li><a href="#api-folder">批量文件转换 API</a></li>
                    <li><a href="#api-folder-md">批量文件转Markdown API</a></li>
                    <li><a href="#api-folder-docling">批量文件转Markdown (Docling) API</a></li>
                    <li><a href="#api-folder-marker">批量文件转Markdown (Marker) API</a></li>
                </ul>
            </section>

            <section id="api-text" class="api-section">
                <h2 data-i18n="api-extract-text">文档文本提取 API</h2>
                <div class="api-endpoint">
                    <h3>POST /api/convert</h3>
                    <div class="api-description">
                        <p>将文档转换为纯文本格式。</p>
                        <p><strong>内容类型:</strong> <code>multipart/form-data</code></p>
                    </div>
                    <div class="api-params">
                        <h4>参数</h4>
                        <ul>
                            <li><strong>file</strong>: 要转换的文件（multipart/form-data）</li>
                        </ul>
                    </div>
                    <div class="api-response">
                        <h4>响应</h4>
                        <pre><code>
{
    "text": "转换后的文本内容...",
    "filename": "原始文件名",
    "status": "success",
    "time_taken": "转换耗时（秒）"
}
                        </code></pre>
                    </div>
                    <div class="api-types">
                        <h4>支持的文件类型</h4>
                        <p>.doc, .docx, .xls, .xlsx, .ppt, .pptx, .pdf, .txt, .md, .csv</p>
                    </div>
                </div>
            </section>

            <section id="api-markitdown-md" class="api-section">
                <h2 data-i18n="api-markitdown-md">MarkItDown转MD API</h2>
                <div class="api-endpoint">
                    <h3>POST /api/convert-to-md</h3>
                    <div class="api-description">
                        <p>使用MarkItDown转换器将文档转换为Markdown格式。</p>
                        <p><strong>内容类型:</strong> <code>multipart/form-data</code></p>
                    </div>
                    <div class="api-params">
                        <h4>参数</h4>
                        <ul>
                            <li><strong>file</strong>: 要转换的文件（multipart/form-data）</li>
                        </ul>
                    </div>
                    <div class="api-response">
                        <h4>响应</h4>
                        <pre><code>
{
    "text": "转换后的Markdown内容...",
    "filename": "原始文件名",
    "status": "success",
    "time_taken": "转换耗时（秒）"
}
                        </code></pre>
                    </div>
                    <div class="api-types">
                        <h4>支持的文件类型</h4>
                        <p>.doc, .docx, .xls, .xlsx, .ppt, .pptx, .pdf, .txt, .md</p>
                    </div>
                </div>
            </section>

            <section id="api-docling-md" class="api-section">
                <h2 data-i18n="api-docling-md">Docling转MD API</h2>
                <div class="api-endpoint">
                    <h3>POST /api/convert-to-md-docling</h3>
                    <div class="api-description">
                        <p>使用Docling转换器将文档转换为Markdown格式。优化了对PDF和图像的处理。</p>
                        <p><strong>内容类型:</strong> <code>multipart/form-data</code></p>
                    </div>
                    <div class="api-params">
                        <h4>参数</h4>
                        <ul>
                            <li><strong>file</strong>: 要转换的文件（multipart/form-data）</li>
                        </ul>
                    </div>
                    <div class="api-response">
                        <h4>响应</h4>
                        <pre><code>
{
    "text": "转换后的Markdown内容...",
    "filename": "原始文件名",
    "status": "success",
    "time_taken": "转换耗时（秒）"
}
                        </code></pre>
                    </div>
                    <div class="api-types">
                        <h4>支持的文件类型</h4>
                        <p>.doc, .docx, .xls, .xlsx, .ppt, .pptx, .pdf, .txt, .md, .mp3, .wav, .csv, .html, .xhtml, .png, .jpg, .jpeg, .tiff, .bmp</p>
                    </div>
                </div>
            </section>

            <section id="api-docling-html" class="api-section">
                <h2 data-i18n="api-docling-html">Docling转HTML API</h2>
                <div class="api-endpoint">
                    <h3>POST /api/convert-to-html-docling</h3>
                    <div class="api-description">
                        <p>使用Docling转换器将文档转换为HTML格式。保留文档结构、表格和图片。</p>
                        <p><strong>内容类型:</strong> <code>multipart/form-data</code></p>
                    </div>
                    <div class="api-params">
                        <h4>参数</h4>
                        <ul>
                            <li><strong>file</strong>: 要转换的文件（multipart/form-data）</li>
                        </ul>
                    </div>
                    <div class="api-response">
                        <h4>响应</h4>
                        <pre><code>
{
    "text": "转换后的HTML内容...",
    "filename": "原始文件名",
    "status": "success",
    "time_taken": "转换耗时（秒）"
}
                        </code></pre>
                    </div>
                    <div class="api-types">
                        <h4>支持的文件类型</h4>
                        <p>.doc, .docx, .xls, .xlsx, .ppt, .pptx, .pdf, .txt, .md, .mp3, .wav, .csv, .html, .xhtml, .png, .jpg, .jpeg, .tiff, .bmp</p>
                    </div>
                </div>
            </section>

            <section id="api-docling-json" class="api-section">
                <h2 data-i18n="api-docling-json">Docling转JSON API</h2>
                <div class="api-endpoint">
                    <h3>POST /api/convert-to-json-docling</h3>
                    <div class="api-description">
                        <p>使用Docling转换器将文档转换为结构化JSON格式。包含文档结构和内容。</p>
                        <p><strong>内容类型:</strong> <code>multipart/form-data</code></p>
                    </div>
                    <div class="api-params">
                        <h4>参数</h4>
                        <ul>
                            <li><strong>file</strong>: 要转换的文件（multipart/form-data）</li>
                        </ul>
                    </div>
                    <div class="api-response">
                        <h4>响应</h4>
                        <pre><code>
{
    "text": {
        "title": "文档标题",
        "content": [
            {
                "type": "paragraph",
                "text": "段落内容..."
            },
            {
                "type": "heading",
                "level": 1,
                "text": "标题内容..."
            },
            {
                "type": "table",
                "content": [...]
            }
        ],
        "metadata": {
            "source": "源文件信息",
            "pages": "页数"
        }
    },
    "filename": "原始文件名",
    "status": "success",
    "time_taken": "转换耗时（秒）"
}
                        </code></pre>
                    </div>
                    <div class="api-types">
                        <h4>支持的文件类型</h4>
                        <p>.doc, .docx, .xls, .xlsx, .ppt, .pptx, .pdf, .txt, .md, .mp3, .wav, .csv, .html, .xhtml, .png, .jpg, .jpeg, .tiff, .bmp</p>
                    </div>
                </div>
            </section>

            <section id="api-marker-md" class="api-section">
                <h2 data-i18n="api-marker-md">Marker转MD API</h2>
                <div class="api-endpoint">
                    <h3>POST /api/convert-to-md-marker</h3>
                    <div class="api-description">
                        <p>使用Marker转换器将文档转换为Markdown格式。具有出色的表格和公式处理能力。</p>
                        <p><strong>内容类型:</strong> <code>multipart/form-data</code></p>
                    </div>
                    <div class="api-params">
                        <h4>参数</h4>
                        <ul>
                            <li><strong>file</strong>: 要转换的文件（multipart/form-data）</li>
                        </ul>
                    </div>
                    <div class="api-response">
                        <h4>响应</h4>
                        <pre><code>
{
    "text": "转换后的Markdown内容...",
    "filename": "原始文件名",
    "status": "success",
    "time_taken": "转换耗时（秒）"
}
                        </code></pre>
                    </div>
                    <div class="api-types">
                        <h4>支持的文件类型</h4>
                        <p>.pdf, .png, .jpg, .jpeg, .pptx, .docx, .xlsx, .html</p>
                    </div>
                </div>
            </section>

            <section id="api-marker-html" class="api-section">
                <h2 data-i18n="api-marker-html">Marker转HTML API</h2>
                <div class="api-endpoint">
                    <h3>POST /api/convert-to-html-marker</h3>
                    <div class="api-description">
                        <p>使用Marker转换器将文档转换为HTML格式。保留文档的完整样式和格式。</p>
                        <p><strong>内容类型:</strong> <code>multipart/form-data</code></p>
                    </div>
                    <div class="api-params">
                        <h4>参数</h4>
                        <ul>
                            <li><strong>file</strong>: 要转换的文件（multipart/form-data）</li>
                        </ul>
                    </div>
                    <div class="api-response">
                        <h4>响应</h4>
                        <pre><code>
{
    "text": "转换后的HTML内容...",
    "filename": "原始文件名",
    "status": "success",
    "time_taken": "转换耗时（秒）"
}
                        </code></pre>
                    </div>
                    <div class="api-types">
                        <h4>支持的文件类型</h4>
                        <p>.pdf, .png, .jpg, .jpeg, .pptx, .docx, .xlsx, .html</p>
                    </div>
                </div>
            </section>

            <section id="api-marker-json" class="api-section">
                <h2 data-i18n="api-marker-json">Marker转JSON API</h2>
                <div class="api-endpoint">
                    <h3>POST /api/convert-to-json-marker</h3>
                    <div class="api-description">
                        <p>使用Marker转换器将文档转换为结构化JSON格式。包含文档元数据和内容结构。</p>
                        <p><strong>内容类型:</strong> <code>multipart/form-data</code></p>
                    </div>
                    <div class="api-params">
                        <h4>参数</h4>
                        <ul>
                            <li><strong>file</strong>: 要转换的文件（multipart/form-data）</li>
                        </ul>
                    </div>
                    <div class="api-response">
                        <h4>响应</h4>
                        <pre><code>
{
    "text": {
        "title": "文档标题",
        "content": [
            {
                "type": "paragraph",
                "text": "段落内容..."
            },
            {
                "type": "heading",
                "level": 1,
                "text": "标题内容..."
            },
            {
                "type": "table",
                "content": [...]
            }
        ],
        "metadata": {
            "author": "作者信息",
            "created": "创建时间",
            "pages": "页数"
        }
    },
    "filename": "原始文件名",
    "status": "success",
    "time_taken": "转换耗时（秒）"
}
                        </code></pre>
                    </div>
                    <div class="api-types">
                        <h4>支持的文件类型</h4>
                        <p>.pdf, .png, .jpg, .jpeg, .pptx, .docx, .xlsx, .html</p>
                    </div>
                </div>
            </section>

            <section id="api-folder" class="api-section">
                <h2>批量文件转换 API</h2>
                <div class="api-endpoint">
                    <h3>POST /api/convert-folder</h3>
                    <div class="api-description">
                        <p>批量将指定文件夹中的所有文档转换为文本格式。</p>
                        <p><strong>内容类型:</strong> <code>application/json</code></p>
                    </div>
                    <div class="api-params">
                        <h4>参数</h4>
                        <ul>
                            <li><strong>source_folder</strong>: 要转换的文件夹路径 (JSON请求参数)</li>
                            <li><strong>output_folder</strong>: 输出文件夹路径 (可选，JSON请求参数)</li>
                        </ul>
                        <h4>请求示例</h4>
                        <pre><code>
{
    "source_folder": "/path/to/documents",
    "output_folder": "/path/to/output"
}
                        </code></pre>
                    </div>
                    <div class="api-response">
                        <h4>响应</h4>
                        <pre><code>
{
    "source_folder": "/path/to/documents",
    "output_folder": "/path/to/output",
    "log_file": "/path/to/output/conversion_log.txt",
    "total_time": 45.23,
    "results": {
        "total_files": 10,
        "converted_files": 8,
        "skipped_files": 1,
        "failed_files": 1,
        "conversion_details": [
            {
                "file": "/path/to/documents/example.docx",
                "status": "success",
                "output": "/path/to/output/example.txt",
                "processing_time": 5.32
            },
            {
                "file": "/path/to/documents/image.jpg",
                "status": "skipped",
                "reason": "不支持的文件格式: .jpg"
            }
        ]
    }
}
                        </code></pre>
                    </div>
                </div>
            </section>

            <section id="api-folder-md" class="api-section">
                <h2>批量文件转Markdown API</h2>
                <div class="api-endpoint">
                    <h3>POST /api/convert-to-md-folder</h3>
                    <div class="api-description">
                        <p>使用MarkItDown转换器批量将指定文件夹中的所有文档转换为Markdown格式。</p>
                        <p><strong>内容类型:</strong> <code>application/json</code></p>
                    </div>
                    <div class="api-params">
                        <h4>参数</h4>
                        <ul>
                            <li><strong>source_folder</strong>: 要转换的文件夹路径 (JSON请求参数)</li>
                            <li><strong>output_folder</strong>: 输出文件夹路径 (可选，JSON请求参数)</li>
                        </ul>
                        <h4>请求示例</h4>
                        <pre><code>
{
    "source_folder": "/path/to/documents",
    "output_folder": "/path/to/output"
}
                        </code></pre>
                    </div>
                    <div class="api-response">
                        <h4>响应</h4>
                        <pre><code>
{
    "source_folder": "/path/to/documents",
    "output_folder": "/path/to/output",
    "log_file": "/path/to/output/conversion_log.txt",
    "total_time": 45.23,
    "results": {
        "total_files": 10,
        "converted_files": 8,
        "skipped_files": 1,
        "failed_files": 1,
        "conversion_details": [
            {
                "file": "/path/to/documents/example.docx",
                "status": "success",
                "output": "/path/to/output/example.md",
                "processing_time": 5.32
            }
        ]
    }
}
                        </code></pre>
                    </div>
                </div>
            </section>

            <section id="api-folder-docling" class="api-section">
                <h2>批量文件转Markdown (Docling) API</h2>
                <div class="api-endpoint">
                    <h3>POST /api/convert-to-md-docling-folder</h3>
                    <div class="api-description">
                        <p>使用Docling转换器批量将指定文件夹中的所有文档转换为Markdown格式。</p>
                        <p><strong>内容类型:</strong> <code>application/json</code></p>
                    </div>
                    <div class="api-params">
                        <h4>参数</h4>
                        <ul>
                            <li><strong>source_folder</strong>: 要转换的文件夹路径 (JSON请求参数)</li>
                            <li><strong>output_folder</strong>: 输出文件夹路径 (可选，JSON请求参数)</li>
                        </ul>
                        <h4>请求示例</h4>
                        <pre><code>
{
    "source_folder": "/path/to/documents",
    "output_folder": "/path/to/output"
}
                        </code></pre>
                    </div>
                    <div class="api-response">
                        <h4>响应</h4>
                        <pre><code>
{
    "source_folder": "/path/to/documents",
    "output_folder": "/path/to/output",
    "log_file": "/path/to/output/conversion_log.txt",
    "total_time": 45.23,
    "results": {
        "total_files": 10,
        "converted_files": 8,
        "skipped_files": 1,
        "failed_files": 1,
        "conversion_details": [
            {
                "file": "/path/to/documents/example.docx",
                "status": "success",
                "output": "/path/to/output/example.md",
                "processing_time": 5.32
            }
        ]
    }
}
                        </code></pre>
                    </div>
                </div>
            </section>

            <section id="api-folder-marker" class="api-section">
                <h2>批量文件转Markdown (Marker) API</h2>
                <div class="api-endpoint">
                    <h3>POST /api/convert-to-md-marker-folder</h3>
                    <div class="api-description">
                        <p>使用Marker转换器批量将指定文件夹中的所有文档转换为Markdown格式。</p>
                        <p><strong>内容类型:</strong> <code>application/json</code></p>
                    </div>
                    <div class="api-params">
                        <h4>参数</h4>
                        <ul>
                            <li><strong>source_folder</strong>: 要转换的文件夹路径 (JSON请求参数)</li>
                            <li><strong>output_folder</strong>: 输出文件夹路径 (可选，JSON请求参数)</li>
                        </ul>
                        <h4>请求示例</h4>
                        <pre><code>
{
    "source_folder": "/path/to/documents",
    "output_folder": "/path/to/output"
}
                        </code></pre>
                    </div>
                    <div class="api-response">
                        <h4>响应</h4>
                        <pre><code>
{
    "source_folder": "/path/to/documents",
    "output_folder": "/path/to/output",
    "log_file": "/path/to/output/conversion_log.txt",
    "total_time": 45.23,
    "results": {
        "total_files": 10,
        "converted_files": 8,
        "skipped_files": 1,
        "failed_files": 1,
        "conversion_details": [
            {
                "file": "/path/to/documents/example.docx",
                "status": "success",
                "output": "/path/to/output/example.md",
                "processing_time": 5.32
            }
        ]
    }
}
                        </code></pre>
                    </div>
                </div>
            </section>
        </main>

        <section id="api-examples" class="api-section">
            <h2>API使用示例</h2>
            
            <h3>使用Python调用文本提取API</h3>
            <pre><code>
import requests

url = "http://localhost:5000/convert"
file_path = "example.pdf"  # 替换为您的文件路径

with open(file_path, "rb") as f:
    files = {"file": (file_path, f)}
    response = requests.post(url, files=files)

if response.status_code == 200:
    result = response.json()
    print("转换成功!")
    print(f"文本内容: {result['text'][:100]}...")  # 打印前100个字符
    print(f"文件名: {result['filename']}")
else:
    print(f"转换失败: {response.json().get('error', '未知错误')}")
            </code></pre>
            
            <h3>使用Python调用Markdown转换API</h3>
            <pre><code>
import requests

# 可以选择不同的转换器: convert-to-md (MarkItDown), convert-to-md-docling (Docling), convert-to-md-marker (Marker)
url = "http://localhost:5000/convert-to-md-marker"
file_path = "example.pdf"  # 替换为您的文件路径

with open(file_path, "rb") as f:
    files = {"file": (file_path, f)}
    response = requests.post(url, files=files)

if response.status_code == 200:
    result = response.json()
    print("转换成功!")
    print(f"Markdown内容: {result['text'][:100]}...")  # 打印前100个字符
    print(f"文件名: {result['filename']}")
    
    # 保存Markdown到文件
    with open("output.md", "w", encoding="utf-8") as md_file:
        md_file.write(result['text'])
    print("Markdown已保存至output.md")
else:
    print(f"转换失败: {response.json().get('error', '未知错误')}")
            </code></pre>
            
            <h3>使用Python调用批量转换API</h3>
            <pre><code>
import requests
import json

url = "http://localhost:5000/convert-folder"  # 也可以使用 convert-to-md-folder, convert-to-md-docling-folder
data = {
    "source_folder": "D:/documents",
    "output_folder": "D:/output"
}

headers = {
    'Content-Type': 'application/json'
}

response = requests.post(url, data=json.dumps(data), headers=headers)

if response.status_code == 200:
    result = response.json()
    print(f"转换完成，总文件数: {result['results']['total_files']}")
    print(f"成功转换: {result['results']['converted_files']} 文件")
    print(f"跳过的文件: {result['results']['skipped_files']} 文件")
    print(f"失败的文件: {result['results']['failed_files']} 文件")
    print(f"日志文件: {result['log_file']}")
else:
    print(f"批量转换失败: {response.json().get('error', '未知错误')}")
            </code></pre>
            
            <h3>使用Python调用Docling HTML转换API</h3>
            <pre><code>
import requests

url = "http://localhost:5000/convert-to-html-docling"
file_path = "example.pdf"  # 替换为您的文件路径

with open(file_path, "rb") as f:
    files = {"file": (file_path, f)}
    response = requests.post(url, files=files)

if response.status_code == 200:
    result = response.json()
    print("转换成功!")
    
    # 保存HTML到文件
    with open("output.html", "w", encoding="utf-8") as html_file:
        html_file.write(result['text'])
    print("HTML已保存至output.html")
else:
    print(f"转换失败: {response.json().get('error', '未知错误')}")
            </code></pre>
        </section>

        <footer>
            <p data-i18n="footer">© 2025 X2Knowledge v0.4.0 - 知识提取器工具 | 使用Flask和JavaScript构建</p>
            <div class="github-links">
                <a href="https://github.com/leonda123/X2Knowledge.git" class="github-link" target="_blank">
                    <svg class="github-icon" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
                        <path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"/>
                    </svg>
                    GitHub
                </a>
                <a href="https://gitee.com/leonda/X2Knowledge.git" class="github-link" target="_blank">
                    <svg class="github-icon" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
                        <path d="M8 0a8 8 0 0 0-8 8 8 8 0 0 0 8 8 8 8 0 0 0 8-8 8 8 0 0 0-8-8zm0.24 3.088a4.912 4.912 0 0 1 4.794 5.542H5.726c-.02 1.311 1.425 1.993 2.761 1.993 1.155 0 2.206-.606 2.657-1.44h2.342a5.083 5.083 0 0 1-5.038 3.392 4.919 4.919 0 0 1-4.82-5.585 4.916 4.916 0 0 1 4.612-3.902z"/>
                    </svg>
                    Gitee
                </a>
            </div>
        </footer>
    </div>
    
    <script src="{{ url_for('static', filename='js/i18n.js') }}"></script>
    <script src="{{ url_for('static', filename='js/main.js') }}"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // API标签切换
            const apiTabButtons = document.querySelectorAll('.api-tab-button');
            const apiTabContents = document.querySelectorAll('.api-tab-content');
            
            apiTabButtons.forEach(button => {
                button.addEventListener('click', function() {
                    // 移除所有active类
                    apiTabButtons.forEach(btn => btn.classList.remove('active'));
                    apiTabContents.forEach(content => content.classList.remove('active'));
                    
                    // 添加active类到当前tab
                    this.classList.add('active');
                    const tabId = this.dataset.tab;
                    document.getElementById(tabId).classList.add('active');
                });
            });
            
            // 检查是否存在语言偏好并应用
            const savedLang = localStorage.getItem('x2knowledge_lang');
            if (savedLang) {
                const langButtons = document.querySelectorAll('.language-btn');
                langButtons.forEach(btn => {
                    if (btn.dataset.lang === savedLang) {
                        btn.click(); // 触发保存的语言按钮点击事件
                    }
                });
            }
        });
    </script>
</body>
</html> 